<%--
  Created by IntelliJ IDEA.
  User: 莫
  Date: 2018/1/8
  Time: 13:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html >
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Login</title>
    <style>
        *{
            margin: 0; /*清楚外边距*/
        }
        html{
            height: 100%;
            font: 16px;
        }
        body{
            display: flex;  /*弹性盒模型*/
            /*主轴方向上内部元素排序方式：居中*/
            justify-content: center;
            /*辅轴方向上内部元素排序方式：居中*/
            align-items: center;
            height: 100%;
            background-image: url(img/timg1.jpg);
        }
        .login-wrap{
            width: 300px;
            height: 300px;
            background-color: rgb(252, 244, 244);
            border-radius: 8px;
        }
        .login-wrap:before{
            display: block;/*以块元素展示*/
            content: '';/*激活伪元素*/
            width: 100%;
            height: 6px;
            /*渐变色 left 从左到右渐变*/
            background: -webkit-linear-gradient(left,#27ae60 0%,#27ae60 20%,#6633ff 20%,#6633ff 40%,#3399ff 40%,#6633ff 60%,#ff0066 60%,#ff0066 80%,#3de93d 80%,#3de93d 100%);
            border-radius: 8px 8px 0 0;/*顺时针*/
        }
        .login-wrap h2{
            font-size: 2em;/*默认16px 具有弹性 以整体字体大小为基础变化*/
            color:#368;
            text-align: center;
            line-height: 80px;
        }
        .login-content{
            /*具备可读性，方便别人知道是哪一个使用这个类名
            非div 元素需要先写元素名*/
            display: flex;/*横向排*/
            /*主轴方向：column纵向 row横向*/
            flex-direction: column;
            /*主轴方向内部元素排序方式，均分*/
            justify-content: space-around;
            /*辅轴方向内部元素排序：居中*/
            align-items: center;
            width: 100%;
            height: 200px;
            background-color: rgb(245, 227, 227);
        }
        .login-content input{
            width: 80%;
            height: 40px;
            /*边框 粗细 样式 颜色*/
            font-size: 1em;
            border: 3px solid #bbb;
            outline: 0;
            text-indent: 1em;/*首行缩进*/
            border-radius: 5px;
        }
        .login-content button{
            width: 80%;
            height: 40px;
            border-top-style: none;
            border-right-style: none;
            border-bottom-style: none;
            border-left-style: none;
            border-radius: 5px;
            background-color: #e99676;
        }
    </style>
</head>
<body>
<div class="login-wrap">
    <!-- 没有实际意义的空标签,用伪元素before after代替<div class="ribon"></div> -->
    <h2>Login</h2>
    <div class="login-content" style="">
        <input type="text" name="user" placeholder="请输入用户名" id="input_useraccountid">
        <input type="password" name="pwd" placeholder="请输入密码" id="input_userpwdid">
        <!-- <input type="submit" value="sign in"> -->
        <button  class="LoginBtn" id="LoginBtnID" onclick="LoginFN()">Sign in</button>
    </div>
</div>
<script src="js/jquery-2.1.1.min.js"></script>
<script>
    var xmlhttp;
    function LoginFN() {
        var input_account = document.getElementById("input_useraccountid").value;
        var input_pwd = document.getElementById("input_userpwdid").value;

        if(input_account == "" || input_pwd == "")
        {
            alert("Invalid value");
            return;
        }
        xmlhttp=new XMLHttpRequest();
        xmlhttp.open("POST","Login4html",false);
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xmlhttp.send("userAccount="+ input_account +"&userPwd=" + input_pwd + "&FN=1");

        var res = JSON.parse(xmlhttp.responseText);
        if(res.Result == "Success")
        {

            CurUserID = res.UserInfo.userID;
            CurUserAccount = res.UserInfo.userAccount;
            CurUserName = res.UserInfo.userName;
            CurUserType  = res.UserInfo.userType;
            CurUserStatus = res.UserInfo.userStatus;

            //Cookie保存
            document.cookie = "CurUserName="+CurUserName;

            if (res.UserInfo.admin==1)
            {
                var str_admin = "NewsManage_Admin.jsp?name="+CurUserName;
                window.location.replace(str_admin);
            }
            else
            {
                var str = "NewsManage.jsp?name="+CurUserName;
                window.location.replace(str);
            }

        }
        else
        {
            alert("UserAccount Or UserPwd Error");
        }
    }
</script>
</body>
</html>
